<?php

/**
 * This is the model class for table "{{student}}".
 *
 * The followings are the available columns in table '{{student}}':
 * @property integer $id
 * @property string $roll_no
 * @property string $enrollment_no
 * @property string $first_name
 * @property string $middle_name
 * @property string $last_name
 * @property string $date_of_birth
 * @property string $date_of_entry
 * @property integer $class_of_entry
 * @property integer $current_class
 * @property integer $academic_session
 * @property string $passport_no
 * @property string $blood_group
 * @property integer $house_id
 * @property integer $sibling_id
 * @property string $created_date
 * @property string $updated
 * @property integer $deleted
 */
class Student extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Student the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return '{{student}}';
	}

	/**
	 * @return array validation rules for model attributes.
	 */
	public function rules()
	{
		// NOTE: you should only define rules for those attributes that
		// will receive user inputs.
		return array(
			array('class_of_entry, current_class, academic_session', 'required'),
			array('class_of_entry, current_class, academic_session, house_id, sibling_id, deleted', 'numerical', 'integerOnly'=>true),
			array('roll_no, enrollment_no', 'length', 'max'=>15),
			array('first_name, middle_name, last_name', 'length', 'max'=>100),
			array('passport_no', 'length', 'max'=>20),
			array('blood_group', 'length', 'max'=>10),
			array('date_of_birth, date_of_entry, created_date, updated', 'safe'),
			array('created_date','default','value'=>new CDbExpression('NOW()'),'setOnEmpty'=>false,'on'=>'insert'),
			array('updated','default','value'=>new CDbExpression('NOW()'),'setOnEmpty'=>false,'on'=>'update'),
			// The following rule is used by search().
			// Please remove those attributes that should not be searched.
			array('id, roll_no, enrollment_no, first_name, middle_name, last_name, date_of_birth, date_of_entry, class_of_entry, current_class, academic_session, passport_no, blood_group, house_id, sibling_id, created_date, updated, deleted', 'safe', 'on'=>'search'),
		);
	}

	/**
	 * @return array relational rules.
	 */
	public function relations()
	{
		// NOTE: you may need to adjust the relation name and the related
		// class name for the relations automatically generated below.
		return array(
		);
	}

	/**
	 * @return array customized attribute labels (name=>label)
	 */
	public function attributeLabels()
	{
		return array(
			'id' => 'ID',
			'roll_no' => 'Roll No',
			'enrollment_no' => 'Enrollment No',
			'first_name' => 'First Name',
			'middle_name' => 'Middle Name',
			'last_name' => 'Last Name',
			'date_of_birth' => 'Date Of Birth',
			'date_of_entry' => 'Date Of Entry',
			'class_of_entry' => 'Class Of Entry',
			'current_class' => 'Current Class',
			'academic_session' => 'Academic Session',
			'passport_no' => 'Passport No',
			'blood_group' => 'Blood Group',
			'house_id' => 'House',
			'sibling_id' => 'Sibling',
			'created_date' => 'Created Date',
			'updated' => 'Updated',
			'deleted' => 'Deleted',
		);
	}

	/**
	 * Retrieves a list of models based on the current search/filter conditions.
	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.
	 */
	public function search()
	{
		// Warning: Please modify the following code to remove attributes that
		// should not be searched.

		$criteria=new CDbCriteria;

		$criteria->compare('id',$this->id);
		$criteria->compare('roll_no',$this->roll_no,true);
		$criteria->compare('enrollment_no',$this->enrollment_no,true);
		$criteria->compare('first_name',$this->first_name,true);
		$criteria->compare('middle_name',$this->middle_name,true);
		$criteria->compare('last_name',$this->last_name,true);
		$criteria->compare('date_of_birth',$this->date_of_birth,true);
		$criteria->compare('date_of_entry',$this->date_of_entry,true);
		$criteria->compare('class_of_entry',$this->class_of_entry);
		$criteria->compare('current_class',$this->current_class);
		$criteria->compare('academic_session',$this->academic_session);
		$criteria->compare('passport_no',$this->passport_no,true);
		$criteria->compare('blood_group',$this->blood_group,true);
		$criteria->compare('house_id',$this->house_id);
		$criteria->compare('sibling_id',$this->sibling_id);
		$criteria->compare('created_date',$this->created_date,true);
		$criteria->compare('updated',$this->updated,true);
		$criteria->compare('deleted','<>1');

		return new CActiveDataProvider(get_class($this), array(
			'pagination'=>array(
    	   		'pageSize'=> ITEMS_PER_PAGE,
    		),
			'criteria'=>$criteria,
			
		));
	}
}